<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/news.css"></link>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><? echo $title ;?></title>
</head>

<?php


/*
 *  A Part of snock project
 *   Author king-of-war
 * Last modified 2009-4-22
 * designed for products update
 */
@session_start();
$root_path = '../'; //set root_path of this dir

error_reporting(E_ALL ^ E_NOTICE); //去除变量为空错误

include_once $root_path . 'admin/class/verify.class.php';
include_once $root_path . 'admin/class/pro.class.php';
include_once $root_path . 'admin/class/fun_common.php';
include_once $root_path . 'admin/class/error.class.php';
$editor = new fun_common($root_path);
$pro = new pro($root_path);
$check = new verify($root_path);
$check->identity_check(3);
$error = new Errmsg();

/*
* check the array $_GET
*/
if ($_GET['act'] != '') {
	$act = $_POST['submit'];
} else {
	$act = '';
}
if ($_GET['id'] != '') {
	$id = $_GET['id'];
} else {
	$id = '2';
	$info = '请选择要编辑的产品';
	$error->error_chinese($info);

	exit;
}
echo $act;

switch ($act) {

	/*
	 *    define file upload moudle
	 *
	 *
	 */
	case '上传' :
		{
			if (isset ($_POST['submit'])) {

				if (is_uploaded_file($_FILES['upfile']['tmp_name'])) {
					$upfile = $_FILES['upfile'];
					$name = $upfile['name'];
					$type = $upfile['type'];
					$size = $upfile['size'];
					$tmp_name = $upfile['tmp_name'];

					switch ($type) {
						case 'image/pjpeg' :
							$ok = 1;
							break;
						case 'image/jpeg' :
							$ok = 1;
							break;
						case 'image/gif' :
							$ok = 1;
							break;
						case 'image/png' :
							$ok = 1;
							break;
						default :
							$ok = 0;
							break;
					}
					if ($ok) {

						move_uploaded_file($tmp_name, '../images/uploads/' . $name);
						if ($upfile['error'] == 0) {
					echo		$dir = 'images/uploads/' . $name;
							$image = $dir;
						} else {
							echo '&Eacute;&Iuml;&acute;&laquo;&Ecirc;&sect;&deg;&Uuml;';
						}

					} else {
						echo '&sup2;&raquo;&Ocirc;&Ecirc;&ETH;&iacute;&acute;&Euml;&Icirc;&Auml;&frac14;&thorn;&Agrave;&agrave;&ETH;&Iacute;';
					}
				}

			}
		}
		break;
		/*
		 * define  products add function
		 *
		 */
	case '提交' :
		{

			/* $fun=1 means add
				 * $fun=0 means update
			 * define the add
			 */
			if (isset ($_POST['submit'])) {

				$name = $_POST['name'];
				$sort_id = $_POST['sort_id'];
				$images = $_POST['pic'];
				$intro = $_POST['comments'];
				$line = $pro->products_add($id, $sort_id, $images, $name, $intro,0);
				if ($line) {
					$info = '产品更新成功';
					$error->error_chinese($info);
					exit;
				} else {
					$info = '产品更新失败';
					$error->error_chinese($info);
					exit;
				}
			}
		}

		break;

		/*
		 * define  products read function
		 */
	default :
		{

			$id = $_GET['id'];

			$pass = $pro->products_get($id);

			$products = array ();

			if (is_array($pass)) {
				$products['id'] = $pass[0]->get_id();
				$products['sort_id'] = $pass[0]->get_sort_id();
				$products['name'] = $pass[0]->get_name();
				$products['image'] = $pass[0]->get_images();
				$products['introduction'] = $pass[0]->get_introduction();

			}

		}

		break;
}

if (isset ($image)) {
	$pic = $image;
}else{
	$pic = $products['image'];
}
echo $pic;
?>

<body>
<div id="news_add">
  <h1>产品添加</h1>
  <form action="pro_update.php?act=submit&&id=<?php echo $id; ?>" enctype="multipart/form-data" method="post"
	name="upform" id="upform">
    <table height="288" width="500">
      <tr>
        <td width="150" height="40" align="right"><label for="name">产品名称：</label></td>
        <td><input type="text" name="name" id="name" value="<?php echo $products['name'] ?>"></td>
        <td><div id="nameTip"></div></td>
      </tr>
      <tr>
        <td height="56" align="right"><label for="author">所属分类： </label></td>
        <td><label>
          <select name="sort_id" id="sort_id">

		<?php


/*
		* get sort comments moudle
		*/
// get the total of sorts


$fun = new fun_common($root_path);
$max = $fun->getAll('products_sort', 1);

// sort operation

include_once $root_path . 'admin/class/sort.class.php';
$sort = new sort($root_path);
$sorts = array ();
// select range te[0] -- te[1]
$te[0] = 0;
$te[1] = $max;
$pass = $sort->sort_read($te);

for ($i = 0; $i < $max; $i++) {
	$sorts[$i]['id'] = $pass[$i]->get_id();
	$sorts[$i]['name'] = $pass[$i]->get_name();
echo '<option value="'.$sorts[$i]['id'].'">'.$sorts[$i]['name'].'</option>';
}


?>
          </select>
        </label></td>
        <td> 产品大类 </td>
      </tr>
      <tr>
        <td height="44" align="right">上传图片：</td>
        <td><input name="upfile" type="file"></td>
        <td>&nbsp;
          <input type="submit" name="submit" value="上传"></td>
      </tr>
      <tr>
        <td height="68" align="right">图片路径：</td>
        <td><input type="text"  name="pic"
			value="<?php echo $pic; ?>"></td>
        <td>上传时请使用英文或拼音，暂不支持中文</td>
      </tr>
      <tr align="right">
        <td height="2" colspan="3">
        <?php


/*
*create the editor
* $name nean names   $w mean width  $h means heidth  $toobar mean toobarset  $value mean value
*/
$name = 'comments';
$w = "600";
$h = "400";
$toobar = "liujie";
$value = $products['introduction'];
$editor->create_editor($name, $h, $w, $toobar, $value);
?></td>
      </tr>
      <tr>
        <td height="62" align="right"><input id="Submit" type="submit"
			name="submit" value="提交"></td>
        <td align="center"><input type="reset" name="reset" value="重置"></td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>



